package com.sunhao.springboot_satoken.config;

import cn.dev33.satoken.stp.StpInterface;
import com.sunhao.springboot_satoken.domain.dos.RoleDo;
import com.sunhao.springboot_satoken.domain.dos.UserDo;
import com.sunhao.springboot_satoken.service.RoleService;
import com.sunhao.springboot_satoken.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @ClassName StpInterfaceImpl
 * @Description
 * @Author SunHao
 * @Date 2025/7/25 12:16
 * @Version 1.0
 **/

@Component
public class StpInterfaceImpl implements StpInterface {

    @Autowired
    private UserService userService;

    @Autowired
    private RoleService roleService;

    /*
     * 权限校验
     * */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        return new ArrayList<>();
    }

    /*
     * 角色校验
     * */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        //loginId
        long userId = Long.parseLong(loginId.toString());

        //根据用户id查询角色信息
        UserDo userDo = userService.selectUserById(userId);

        Long roleId = userDo.getRoleId();
        RoleDo roleDo = roleService.selectRoleById(roleId);
        String roleCode = roleDo.getRoleCode();
        List<String> roleList = new ArrayList<>();
        if (roleCode!=null) {
            roleList.add(roleCode);
        }
        return roleList;
    }
}
